Skip to content

Conversation

@xhpohanka
Copy link
Contributor

It might be handy to select all files from a subdirectory when doing code relocation.

This allow to use ** wildcard in zephyr_code_relocate cmake macro
to match files in any subdirectory.

Signed-off-by: Jan Pohanka <[email protected]>
Add details how the files are searched using zephyr_code_relocate
cmake macro.

Signed-off-by: Jan Pohanka <[email protected]>
@carlescufi
Copy link
Member

@andyross @tejlmand could you please review?

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems very reasonable, though technically this is an API change that will select different files for existing apps. This is a rarely-used feature though, so maybe not a big deal.

@fabiobaltieri fabiobaltieri added this to the v3.3.0 milestone Sep 20, 2022
Copy link
Contributor

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not opposed to the change or functionality, but have some concerns that must be addressed first, before a +1.

mem_region, copy_flag, file_name = line.split(':', 2)

file_name_list = glob.glob(file_name)
file_name_list = glob.glob(file_name, recursive=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not opposed to the change itself, but do we have risk of side-effects ?

What happens in systems that might be building Zephyr inside Zephyr, or re-using source code.
Here a candidate could be TF-M which can build MCUboot as a secure bootloader.

Before approving this change, I would really like you to describe what problem you're solving, rather than just It might be handy.

Especially because the feature is not widely used, the risk is that side-effects are not discovered, as well as they could be hard to debug.

Should the proposed solution be configurable through an argument to this script ?
which then can be enable in Kconfig, similar to CONFIG_CODE_DATA_RELOCATION.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look at the comments next week or the week after, once I'm back from the mountains...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main use case was this (the project runs on stm32h7x with plenty RAM free space and slow quadspi flash)

zephyr_code_relocate(${ZEPHYR_BASE}/subsys/**/*.c SRAM2_TEXT )
zephyr_code_relocate(${ZEPHYR_BASE}/drivers/**/*.c SRAM2_TEXT )

Relocating the zephyr system files lead to great speed up in my case. Specifying each subfolder in the example is definitely an option, but for me it increases complexity.

Original documentation of the zephyr_code_relocate macro is quite insufficient. When I read limited regexp support I had to go to the source and there I got the idea to add the recursive flag.

I agree it could possibly break some older code, but I have not found any usage now...

@tejlmand
Copy link
Contributor

This PR start to look related to the effort carried out here: #50792

If so, please do not merge either of the PRs, until it has been settled which direction to take.
I don't like to have too many variation on accomplishing the same goal.

@danieldegrasse
Copy link
Contributor

#50792 is dependent on #50791, which adds zephyr_library_relocate to the build system- the intention of this macro is to allow entire Zephyr libraries to be relocated. This would allow an entire driver, the kernel itself, or any subsystem to be relocated.

@xhpohanka, I think this implementation might be more flexible, but I agree that a flag would be useful here, similar to the COPY flag this macro currently optionally supports. Do you have any issue with this approach?

@xhpohanka
Copy link
Contributor Author

I personally think that these two approaches don't go against each other.

My solution is based on idea that I want to relocate all files on some path. In my usecase it is easier, because I don't bother what libraries are there.

The second one is thinking in opposite way (relocate a library and don't bother what files the library use).

@tejlmand
Copy link
Contributor

tejlmand commented Oct 4, 2022

I personally think that these two approaches don't go against each other.

Not necessarily, but I wanted to ensure that especially your use-case was not covered by the library proposal.

My solution is based on idea that I want to relocate all files on some path. In my usecase it is easier, because I don't bother what libraries are there.

So in this case, let's continue, but adjust your proposal.
Instead of adjusting the python script, then we should improve on the CMake side.

A disadvantage of the Python script is that it's much harder for users to directly debug which files got included.
Also the glob will run on each build, thus slowing incremental builds.

Instead the zephyr_code_relocate() should be extended to support a list of files.

This will allow a user to do:

file(GLOB_RECURSIVE relocate_sources "*.c")
zephyr_code_relocate(${relocate_sources} <location>)

or if only a single level is desired

file(GLOB relocate_sources "src/*.c")
zephyr_code_relocate(${relocate_sources} <location>)

this will provide much more freedom to users as to how they want to glob files.
Also it has the benefit on being executed at configure time, thus not impacting incremental builds.

Users can easily see which files are included for relocation by using --trace-expand or a message() / print() function in CMake.
They can even look directly in the Makefile or build.ninja.

This proposal will require a small change on how arguments in zephyr_code_relocate() is handled.

Combining this with support for generator expression, as commented here:
#50791 (comment)

This means a single solution should be able to support both ways.

Side note: as part of this, we could consider to deprecate support for the regex in the python script itself, but that would be outside the scope for the above proposal.

@xhpohanka
Copy link
Contributor Author

I totally agree, cmake solution would be better.

@tejlmand
Copy link
Contributor

@xhpohanka #50791 has been updated to support list of files.
Feel free to join the discussion in that PR, and if you believe it solves your use-case, then feel free to close this PR.

@gmarull gmarull removed their request for review October 13, 2022 12:09
@xhpohanka
Copy link
Contributor Author

closing in favor of #50791

@xhpohanka xhpohanka closed this Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants